#ifndef MAP_H
#define MAP_H

#include "tileset.h"
#include <qstring.h>
#include <qfile.h>

#include "unit.h"

struct MapSquare
{
    quint16 tile;
    quint8 character;
    quint8 event;
};

class Map
{
public:
    Map(const QString& filePath, Tileset& tileset, bool forceCreation = true,
        const QString& name = "Undefined", quint8 width = 25, quint8 height = 18);
    virtual ~Map();

    void save();
    void read();

    const QString& getName() const;
    quint8 getWidth() const;
    quint8 getHeight() const;

    //TILES
    //Sets the (y,x) entry of the matrix to a given value
    void modifyTile(quint8 x, quint8 y, quint16 value);
    void fillTiles(quint16 value);
    const Tile& getTile(quint8 x, quint8 y) const;
    quint16 getTileNumber(quint8 x, quint8 y) const; // pour enreg dans le fichier pour une gamemap

    //CHARACTERS
    void resetCharacters();
    void putCharacter(quint8 x, quint8 y, quint16 value);
    void removeCharacter(quint8 x, quint8 y);
    void putSpawnPoint(quint8 x, quint8 y);
    quint8 getCharacterNumber(quint8 x, quint8 y) const;
    bool containsCharacter(quint8 x, quint8 y) const;
    bool containsSpawnPoint(quint8 x, quint8 y) const;
    bool containsNoUnit(quint8 x, quint8 y) const;

    //EVENTS
    void resetEvents();


protected:
    QString m_name;
    QFile m_file;
    Tileset& m_tileset;
    MapSquare** m_matrix;
    quint8 m_width;
    quint8 m_height;


};

#endif // MAP_H
